Public Class SharePointDriver
    Inherits NHibernate.Driver.DriverBase
    Implements NHibernate.AdoNet.IEmbeddedBatcherFactoryProvider, NHibernate.Driver.ISqlParameterFormatter

    Private _connectionString As String

    Public Overrides Sub Configure(ByVal settings As System.Collections.Generic.IDictionary(Of String, String))
        If settings.ContainsKey("connection.connection_string") = True Then
            _connectionString = settings.Item("connection.connection_string")
        End If
    End Sub

    Protected Overrides ReadOnly Property SupportsPreparingCommands() As Boolean
        Get
            Return True
        End Get
    End Property
    Public Overrides Function CreateConnection() As System.Data.IDbConnection
        Return New SharePointClient.Connection(_connectionString)
    End Function

    'Public Overrides Function GenerateCommand(ByVal type As System.Data.CommandType, ByVal sqlString As SqlCommand.SqlString, ByVal parameterTypes() As SqlTypes.SqlType) As System.Data.IDbCommand
    '    Dim cmd As New SharePointClient.Command
    '    cmd.CommandType = type
    '    cmd.CommandText = sqlString.ToString
    '    For Each t As SqlTypes.SqlType In parameterTypes
    '        Dim p As New System.Data.SharePointClient.DataParameter
    '        With t
    '            p.DbType = t.DbType
    '            If t.PrecisionDefined = True Then
    '                p.Precision = t.Precision
    '                p.Scale = t.Scale
    '            End If
    '        End With
    '        cmd.Parameters.Add(p)
    '    Next
    '    Return cmd
    'End Function

    Public Overrides ReadOnly Property SupportsMultipleOpenReaders() As Boolean
        Get
            Return False
        End Get
    End Property

    Public Overrides ReadOnly Property SupportsMultipleQueries() As Boolean
        Get
            Return False
        End Get
    End Property

    Public Sub New()

    End Sub

    Public ReadOnly Property BatcherFactoryClass() As System.Type Implements AdoNet.IEmbeddedBatcherFactoryProvider.BatcherFactoryClass
        Get
            Return GetType(SharePointBatcherFactory)
        End Get
    End Property

    Public Overrides ReadOnly Property UseNamedPrefixInSql() As Boolean
        Get
            Return True
        End Get
    End Property
    Public Overrides ReadOnly Property UseNamedPrefixInParameter() As Boolean
        Get
            Return True
        End Get
    End Property
    Public Overrides ReadOnly Property NamedPrefix() As String
        Get
            Return "@"
        End Get
    End Property
    Public Overrides Function CreateCommand() As System.Data.IDbCommand
        Return New System.Data.SharePointClient.Command()
    End Function

    Protected Overrides Sub InitializeParameter(ByVal dbParam As System.Data.IDbDataParameter, ByVal name As String, ByVal sqlType As SqlTypes.SqlType)
        MyBase.InitializeParameter(dbParam, name, sqlType)
    End Sub

End Class

Public Class SharePointBatcherFactory
    Implements NHibernate.AdoNet.IBatcherFactory

    Dim factory As New NHibernate.AdoNet.NonBatchingBatcherFactory()
    Public Function CreateBatcher(ByVal connectionManager As AdoNet.ConnectionManager, ByVal interceptor As IInterceptor) As Engine.IBatcher Implements AdoNet.IBatcherFactory.CreateBatcher
        Return factory.CreateBatcher(connectionManager, interceptor)
    End Function
End Class

Public Class SharePointBatcher
    Inherits NHibernate.AdoNet.AbstractBatcher

    Private _connMgr As AdoNet.ConnectionManager
    Private _Interceptor As IInterceptor

    Private _NonBatcher As NHibernate.Engine.IBatcher

    Public Sub New(ByVal ConnectionManager As AdoNet.ConnectionManager, ByVal interceptor As IInterceptor)
        MyBase.New(ConnectionManager, interceptor)

        _NonBatcher = New NHibernate.AdoNet.NonBatchingBatcherFactory().CreateBatcher(ConnectionManager, interceptor)
    End Sub

    Public Overrides Sub AddToBatch(ByVal expectation As AdoNet.IExpectation)
        _NonBatcher.AddToBatch(expectation)
    End Sub

    Public Overrides Property BatchSize() As Integer
        Get
            Return _NonBatcher.BatchSize
        End Get
        Set(ByVal value As Integer)
            _NonBatcher.BatchSize = value
        End Set
    End Property

    Protected Overrides Sub DoExecuteBatch(ByVal ps As System.Data.IDbCommand)

    End Sub
End Class